import pandas as pd

data1 = pd.read_csv(r"/Users/tanxiong/Documents/test.csv",sep=",",encoding="UTF-8")

"""
处理数据中存在空值的场景：
"""
print(data1)
print("dropna data :\n{}".format(data1.dropna()))
print("dropna(how=\"all\") data :\n{}".format(data1.dropna(how="all")))
print("data1 info :\n {}".format(data1.info()))
print("data1 fillna:\n {}".format(data1.fillna(0))) ##NaN  的数据全部填充为0
print("data1 fillna:\n{}".format(data1.fillna({"性别":"男"})))

"""
处理数据去重场景：
"""
data2 = pd.read_csv(r"/Users/tanxiong/Documents/test2.csv",sep=",",encoding="UTF-8")
print(data2)
print("去重 dorp_duplicates():\n{}".format(data2.drop_duplicates()))
print("根据某几列确定唯一去重,默认保留第一个：\n{}".format(data2.drop_duplicates(subset=["姓名","唯一码"])))###默认保留第一个
print("根据某几列确定唯一去重，制定保留最后一个：\n{}".format(data2.drop_duplicates(subset=["姓名","唯一码"],keep="last"))) #指定保留最后一个
print("根据某几列确定唯一去重，不保留重复只：\n{}".format(data2.drop_duplicates(subset=["姓名","唯一码"],keep=False)))
data2.replace(to_replace="NaN",value="男")

#data3 = pd.DataFrame({"a":"A","b":"B"})
#data3.replace(to_replace="NaN",value="男")
print("replace 替换值 data2\n{}".format(data2.replace(to_replace="NaN",value="男")))
print("replace 替换值 data2 values\n{}".format(data2.replace(to_replace="李谷",value="李鼓鼓")))



